package com.galeno.yarn2;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;


/**
 * @author galeno
 * @Title:
 * @Description:
 * @date 2021/7/2511:02
 */
public class DriverClass {
    public static void main(String[] args) throws Exception {
        System.setProperty("HADOOP_USER_NAME","root");
        //创建一个配置对象
        Configuration conf=new Configuration();

        // 1 设置运行模式为 yarn
        conf.set("mapreduce.framework.name", "yarn");
        // 2 resourcemanage节点的位置
        conf.set("yarn.resourcemanager.hostname", "galeno01");
        //3 设置处理的数据为HDFS
        conf.set("fs.defaultFS", "hdfs://galeno01:8020");
        // 4 跨平台参数
//        conf.set("mapreduce.app-submission.cross-platform","true");
        // 初始化一个Job
        Job job = Job.getInstance(conf, "wordcount");
        // 5 打包 指定jar包的位置
        job.setJar("d://demo.jar");
        //设置map类
        job.setMapperClass(WordCountMapper.class);
        //设置reducer类
        job.setReducerClass(WordCountReducer.class);
        //设置map和Reducer类的输出类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        //数据的输入路径
        FileInputFormat.setInputPaths(job,new Path("/word.txt"));

        //输出的结果保存路径
        FileOutputFormat.setOutputPath(job,new Path("/wcdata"));
        //运行job等待程序运行完毕
        job.waitForCompletion(true);


    }



}
